package com.yalpuz.wechat.util;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections.CollectionUtils;

import java.util.Iterator;
import java.util.Map;
import java.util.TreeSet;

public class WeChatUtils {

	public static String sha1(Map map) {
		TreeSet<Object> set = new TreeSet<>(map.keySet());
		Iterator<Object> iterator = set.iterator();
		StringBuilder builder = new StringBuilder();
		while (iterator.hasNext()) {
			Object key = iterator.next();
			Object value = map.get(key);
			builder.append(value);
		}
		return DigestUtils.sha1Hex(builder.toString());
	}
	public static String sha1(String...arr) {
		TreeSet<Object> set = new TreeSet<>();
		CollectionUtils.addAll(set,arr);
		Iterator<Object> iterator = set.iterator();
		StringBuilder builder = new StringBuilder();
		while (iterator.hasNext()) {
			Object value = iterator.next();
			builder.append(value);
		}
		return DigestUtils.sha1Hex(builder.toString());
	}


}
